<script type="text/javascript">
    (function($){
        $(document).ready(function() {
            $("#service_main").change(function() {    
                $("#service_sub").load(
                    base_url + "index.php/service/subcategory/"+ $("#service_main").val(),
                    function() {
                        var number_option = $('#service_sub option').size();
                        if(number_option > 1)
                            $("#row_subcategory").show('slow');
                        else
                            $("#row_subcategory").hide('slow');
                    });
            });
            
            var clone_id = 0;
            $('img.make').click(function(e) {                
                if(clone_id != 4)
                    $('#row_make' + clone_id).clone(true).attr('id', 'row_make' + (++clone_id)).appendTo('#body_service');
                e.preventDefault();
            });            
        });        
    })(jQuery);
</script>
<?php 
    echo form_open(base_url()."index.php/service/submit", array('id' => 'targets')); 
?>
    <h1 class="blue">Service</h1>    
    <input type="hidden" name="member" value="<?php echo $this->session->userdata('userid'); ?>" />
    <table>
        <tbody id="body_service">
            <tr>
                <td>
                    <span class="mandatory">Member name</span>
                </td>
                <td>
<?php
                    echo $this->session->userdata('name');
?>
                </td>
            </tr>
            <tr>
                <td>
                    <span class="mandatory">Type of Service</span>
                </td>
                <td>
                    <select name="service[]" class="mandatory" id="service_main">
                        <option value="">Please select</option>
<?php 
                    foreach($service->result() as $row)
                    { 
?>
                        <option value="<?php echo $row->id; ?>">
<?php 
                            echo $row->name;
?>
                        </option>
<?php
                    }
?>      
                    </select>                    
                </td>
            </tr>
            <tr id="row_subcategory">
                <td>
                    <span class="mandatory">Sub-category</span>
                </td>
                <td>
                    <select name="service[]" class="mandatory" id="service_sub">
                        <option value="">Please select</option>
                    </select>                    
                </td>
            </tr>
            <tr>
                <td>
                    Location:
                </td>
                <td>
                    <select name="location">
                        <option value="0">Please select</option>
<?php 
                    foreach($location->result() as $row)
                    { 
?>
                        <option value="<?php echo $row->id; ?>">
<?php 
                            echo $row->province;
?>
                        </option>
<?php
                    }
?>      
                    </select>                    
                </td>
            </tr>
            <tr id="row_make0">
                <td>Make</td>
                <td>        
                    <select name="make[]" id="make" style="min-width: 231px">
                        <option value="0">Please select</option>
<?php 
                    foreach($make->result() as $row)
                    { 
?>
                        <option value="<?php echo $row->id; ?>">
<?php 
                            echo $row->name;
?>
                        </option>
<?php
                    }
?>                              
                    </select>
                    <img class="make" alt="One more make" title="Click to add one more make" src="<?php echo base_url(); ?>system/public/img/add.png" style="vertical-align: middle;"/>                    
                </td>
            </tr>            
        </tbody>
        <tfoot>
            <tr>
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="submit" value="Register" name="submit" class="register" />
                </td>
            </tr>            
        </tfoot>
    </table>
<?php  
    echo form_close();
?>